import axios from "axios";

// 添加基础地址路径
let instance = axios.create({
  baseURL: "/api",
  timeout: 5000,
});
// 设置请求拦截器
instance.interceptors.request.use((config) => {
  let token = localStorage.getItem("token");
  if (token) {
    config.headers.token = token;
  }
  return config;
});
// 设置响应拦截
instance.interceptors.response.use((res) => {
  if (res.data?.data?.token) {
    localStorage.setItem("token", res.data.data.token);
  }
  return res.data;
});
export default instance;
